/*
 * ExtractorAnalyzer.cpp
 *
 *  Created on: Nov 20, 2008
 *      Author: Ryan
 */

#include "ExtractorAnalyzer.h"

#include "../../../OOInterface/Objects/Units/UnitAspects/ResourceExtractorAspect.h"

ExtractorAnalyzer::ExtractorAnalyzer(  OOInterface::AIInterface* i, OOInterface::ConstPlayerPtr self ) :
	_i( i ), _self( self )
{
}

ExtractorAnalyzer::~ExtractorAnalyzer()
{
}

void ExtractorAnalyzer::visitUnit( const OOInterface::Unit& u )
{

	const OOInterface::ResourceList& resources = _i->getResourceTypes();

	int resourceCount = 0;

	float buildingCost = 0.0f;
	float totalResourcesAvailable = 0.0f;

	for( OOInterface::ResourceList::const_iterator resource = resources.begin(); resource != resources.end(); ++resource)
	{
		buildingCost += u.getResourceCost( *resource );
		totalResourcesAvailable += _self->getResourceAmount( *resource );

		++resourceCount;
	}

	if( totalResourcesAvailable != 0.0f )
		_rating -= buildingCost / totalResourcesAvailable;
	else
		_rating -= buildingCost;

}

void ExtractorAnalyzer::visitAirAspect( const OOInterface::AirAspect& a )
{
}

void ExtractorAnalyzer::visitLandAspect( const OOInterface::LandAspect& a )
{
}

void ExtractorAnalyzer::visitWaterAspect( const OOInterface::WaterAspect& a )
{

}

void ExtractorAnalyzer::visitBuilderAspect( const OOInterface::BuilderAspect& a )
{

}

void ExtractorAnalyzer::visitBuildingAspect( const OOInterface::BuildingAspect& a )
{

}

void ExtractorAnalyzer::visitTransportAspect( const OOInterface::TransportAspect& a )
{
}


void ExtractorAnalyzer::visitReclaimableAspect( const OOInterface::ReclaimableAspect& a )
{
}

void ExtractorAnalyzer::visitResourceExtractorAspect( const OOInterface::ResourceExtractorAspect& a )
{
	const OOInterface::ResourceList& resources = _i->getResourceTypes();

	for( OOInterface::ResourceList::const_iterator resource = resources.begin(); resource != resources.end(); ++resource)
	{
		_rating += a.getAmountGenerated(*resource, _i->getGameMap(), _loc );
	}
}
